package logic

import (
	"context"
	"houses_srv/housesclient"
	"houses_srv/models"

	"houses_srv/houses"
	"houses_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListUserLogic {
	return &ListUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListUserLogic) ListUser(in *houses.ListUserRequest) (*houses.ListUserResponse, error) {
	// todo: add your logic here and delete this line

	var a models.User
	user, err := a.ListUser(int(in.Status))
	if err != nil {
		return nil, err
	}

	var userList []*housesclient.ListUser
	for _, u := range user {
		list := housesclient.ListUser{
			UserId: int64(u.ID),
			Nick:   u.Nick,
			Mobile: u.Mobile,
		}
		userList = append(userList, &list)
	}

	return &houses.ListUserResponse{List: userList}, nil
}
